using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Publishing.WebControls;
using Microsoft.SharePoint.Publishing.Fields;

namespace SharePointing.Features.MetaTags.Controls
{
    #region SimpleToolbar
    /// A simple toolbar class that matches the styles of the
    /// publishing field control toolbars.
    public class SimpleToolbar : RepeatedControls
    {
        public SimpleToolbar()
        {
            this.HeaderHtml = "<div class=\"ms-toolbarContainer\" width=\"100%\">";
            this.FooterHtml = "</div>";
            this.SeparatorHtml = "";
        }

        public void AddToolbarButton(string buttonId, string buttonText, string clientOnClick, string tooltipText)
        {
            Literal buttonMarkupLiteral = new Literal();

            buttonMarkupLiteral.Text = String.Format(
                    SimpleToolbarButtonHtmlFormat,
                    SPHttpUtility.HtmlEncode(buttonText),
                    SPHttpUtility.HtmlEncode(clientOnClick),
                    SPHttpUtility.HtmlEncode(tooltipText));
            buttonMarkupLiteral.ID = buttonId;

            this.Controls.Add(buttonMarkupLiteral);
        }

        public void AddToolbarButton(string buttonId, string buttonText, string clientOnClick, string tooltipText, string buttonImageSrc)
        {
            Literal buttonMarkupLiteral = new Literal();

            buttonMarkupLiteral.Text = String.Format(
                    SimpleToolbarButtonImageHtmlFormat,
                    SPHttpUtility.HtmlEncode(buttonText),
                    SPHttpUtility.HtmlEncode(clientOnClick),
                    SPHttpUtility.HtmlEncode(tooltipText),
                    SPHttpUtility.HtmlUrlAttributeEncode(buttonImageSrc));
            buttonMarkupLiteral.ID = buttonId;

            this.Controls.Add(buttonMarkupLiteral);
        }

        // {0} = Button text
        // {1} = onclick script
        // {2} = Tooltip text
        private const string SimpleToolbarButtonHtmlFormat = @"
        <DIV class=""ms-toolbarItem ms-selectorlink"">
           <A href=""#"" onclick=""{1}"" title=""{2}"">&nbsp;{0}</A>
        </DIV>";

        // {0} = Button text
        // {1} = onclick script
        // {2} = Tooltip text
        // {3} = Button image markup
        private const string SimpleToolbarButtonImageHtmlFormat = @"
        <DIV class=""ms-toolbarItem ms-selectorlink"">
           <A href=""#"" onclick=""{1}"" title=""{2}"">
           <IMG alt=""{2}"" src=""{3}"" border=""0"">{0}</A>
        </DIV>";
    }
    #endregion
}
